package edu.java.homework.hw09.exercises.salads.components;

public class Components {

    // --- Instance Variables --------------------------------------------------
    private VegetableComponent[] vegetableComponents = null;
    private FruitComponent[] fruitComponents = null;
    private MeatComponent[] meatComponents = null;
    private MilkComponent[] milkComponents = null;
    private EggComponent[] eggComponents = null;
    private SpiceComponent[] spiceComponents = null;

    // --- Constructors --------------------------------------------------------
    public Components() {
	this(null, null, null, null, null, null);
    }

    public Components(VegetableComponent[] veg, FruitComponent[] fruit,
	    MeatComponent[] meat, MilkComponent[] milk, EggComponent[] egg,
	    SpiceComponent[] spice) {
	vegetableComponents = veg;
	fruitComponents = fruit;
	meatComponents = meat;
	milkComponents = milk;
	eggComponents = egg;
	spiceComponents = spice;
    }

    // --- Methods -------------------------------------------------------------
    @Override
    public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append("Salad Components: \n");
	sb.append(toStringVegetables() + "\n");
	sb.append(toStringFruits() + "\n");
	sb.append(toStringMeat() + "\n");
	sb.append(toStringMilk() + "\n");
	sb.append(toStringEgg() + "\n");
	sb.append(toStringSpice() + "\n");

	return sb.toString();

    }

    public String toStringVegetables() {
	StringBuilder sb = new StringBuilder();
	sb.append("Vegetables: ");
	VegetableComponent[] vegs = getVegetableComponents();
	if (vegs == null) {
	    sb.append("---");
	} else {
	    int length = vegs.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(vegs[i].getVegetable().toString() + ", ");
	    }
	    sb.append(vegs[length - 1].getVegetable().toString());
	}

	return sb.toString();
    }

    public String toStringFruits() {
	StringBuilder sb = new StringBuilder();
	sb.append("Fruits: ");
	FruitComponent[] fruits = getFruitComponents();
	if (fruits == null) {
	    sb.append("-");
	} else {
	    int length = fruits.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(fruits[i].getFruit().toString() + ", ");
	    }
	    sb.append(fruits[length - 1].getFruit().toString());
	}

	return sb.toString();
    }

    public String toStringMeat() {
	StringBuilder sb = new StringBuilder();
	sb.append("Meat Products: ");
	MeatComponent[] meatComponents = getMeatComponents();
	if (meatComponents == null) {
	    sb.append("-");
	} else {
	    int length = meatComponents.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(meatComponents[i].getMeatProduct().toString() + ", ");
	    }
	    sb.append(meatComponents[length - 1].getMeatProduct().toString());
	}

	return sb.toString();
    }

    public String toStringMilk() {
	StringBuilder sb = new StringBuilder();

	sb.append("Milk Products: ");
	MilkComponent[] milkComponents = getMilkComponents();
	if (milkComponents == null) {
	    sb.append("-");
	} else {
	    int length = milkComponents.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(milkComponents[i].getMilkProduct().toString() + ", ");
	    }
	    sb.append(milkComponents[length - 1].getMilkProduct().toString());
	}

	return sb.toString();
    }

    public String toStringEgg() {
	StringBuilder sb = new StringBuilder();

	sb.append("Egg Products: ");
	EggComponent[] eggComponents = getEggComponents();
	if (eggComponents == null) {
	    sb.append("-");
	} else {
	    int length = eggComponents.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(eggComponents[i].getEggProduct().toString() + ", ");
	    }
	    sb.append(eggComponents[length - 1].getEggProduct().toString());
	}

	return sb.toString();
    }

    public String toStringSpice() {
	StringBuilder sb = new StringBuilder();
	sb.append("Spices: ");
	SpiceComponent[] spices = getSpiceComponents();
	if (spices == null) {
	    sb.append("-");
	} else {
	    int length = spices.length;
	    for (int i = 0; i <= length - 2; i++) {
		sb.append(spices[i].getSpice().toString() + ", ");
	    }
	    sb.append(spices[length - 1].getSpice().toString());
	}

	return sb.toString();
    }

    // --- Getters and Setters -------------------------------------------------

    public VegetableComponent[] getVegetableComponents() {
	return vegetableComponents;
    }

    public void setVegetableComponents(VegetableComponent[] vegetableComponents) {
	this.vegetableComponents = vegetableComponents;
    }

    public FruitComponent[] getFruitComponents() {
	return fruitComponents;
    }

    public void setFruitComponents(FruitComponent[] fruitComponents) {
	this.fruitComponents = fruitComponents;
    }

    public MeatComponent[] getMeatComponents() {
	return meatComponents;
    }

    public void setMeatComponents(MeatComponent[] meatComponents) {
	this.meatComponents = meatComponents;
    }

    public MilkComponent[] getMilkComponents() {
	return milkComponents;
    }

    public void setMilkComponents(MilkComponent[] milkComponents) {
	this.milkComponents = milkComponents;
    }

    public EggComponent[] getEggComponents() {
	return eggComponents;
    }

    public void setEggComponents(EggComponent[] eggComponents) {
	this.eggComponents = eggComponents;
    }

    public SpiceComponent[] getSpiceComponents() {
	return spiceComponents;
    }

    public void setSpiceComponents(SpiceComponent[] spiceComponents) {
	this.spiceComponents = spiceComponents;
    }

}
